package com.java2207.group1.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.java2207.group1.bo.EntertainmentBo;
import com.java2207.group1.pojo.Entertainment;
import com.java2207.group1.service.EntertainmentService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("prototype")     // 注意 这里要设置成多例模式
public class WebEntertainmentListener extends AnalysisEventListener<EntertainmentBo> {

    @Autowired
    EntertainmentService entertainmentService;


    @Override
    public void invoke(EntertainmentBo data, AnalysisContext analysisContext) {
        System.out.println(data);
        Entertainment entertainment = new Entertainment();
        //student.setName(data.getName());
        // 属性拷贝
        BeanUtils.copyProperties(data,entertainment);
        entertainmentService.addEntertainment(entertainment);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
